﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Escape
{

    enum Mode
    {
        ceiling, floor
    }

    class Face
    {


        VertexPositionNormalTexture[] v = new VertexPositionNormalTexture[6];
        VertexBuffer vb;


        public Face(int offX, int offZ, Mode m)
        {

            v[0].Position = new Vector3(offX, -1.0f, offZ);
            v[1].Position = new Vector3(offX, -1.0f, offZ - 1.0f);
            v[2].Position = new Vector3(offX + 1.0f, -1.0f, offZ);

            v[3].Position = new Vector3(offX + 1.0f, -1.0f, offZ);
            v[4].Position = new Vector3(offX, -1.0f, offZ - 1.0f);
            v[5].Position = new Vector3(offX + 1.0f, -1.0f, offZ - 1.0f);

            v[0].TextureCoordinate = new Vector2(0.0f, 1.0f);
            v[1].TextureCoordinate = new Vector2(0.0f, 0.0f);
            v[2].TextureCoordinate = new Vector2(1.0f, 1.0f);

            v[3].TextureCoordinate = new Vector2(1.0f, 1.0f);
            v[4].TextureCoordinate = new Vector2(0.0f, 0.0f);
            v[5].TextureCoordinate = new Vector2(1.0f, 0.0f);

            for (int i = 0; i < 6; i++)
                v[i].Normal = Vector3.Up;

            if (m == Mode.ceiling)
            {
                for (int i = 0; i < 6; i++)
                    v[i].Position.Y = 0.0f;
            }

            vb = new VertexBuffer(Basic.device, typeof(VertexPositionNormalTexture), 6, BufferUsage.WriteOnly);
            vb.SetData(v);
        }

        public void Render()
        {
            Basic.device.SetVertexBuffer(vb);
            Basic.device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
        }
    }

}